package com.youuvs.feign;

//import com.youuvs.domain.UserTicket;
//import com.youuvs.domain.UserTicket;
import com.youuvs.domain.UserTicket;
import com.youuvs.result.JSONResult;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(name="service-userTicket",fallbackFactory = UserTicketFeignFallbackFactory.class )
@RequestMapping("/userTicket")
//@Repository
public interface UserTicketFeign {
    @RequestMapping(value="/save",method= RequestMethod.POST)
    JSONResult saveOrUpdate(@RequestBody UserTicket userTicket);

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    JSONResult get(@PathVariable("id")Long id);
}


@Component
class UserTicketFeignFallbackFactory implements FallbackFactory<UserTicketFeign>{

    @Override
    public UserTicketFeign create(Throwable throwable) {
        return new UserTicketFeign() {
            @Override
            public JSONResult saveOrUpdate(UserTicket userTicket) {
                return new JSONResult().setMessage("熔断辣");
            }

            @Override
            public JSONResult get(Long id) {
                return new JSONResult().setMessage("熔断辣");
            }
        };
    }
}
